package com.honkentuber;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author ptucker
 */
public class TimingLogger {
  public static class Timing {
    public Timing(long timeMs, String label) {
      this.timeMs = timeMs;
      this.label = label;
    }

    public final long timeMs;
    public final String label;
  }

  private List<Timing> timings = new ArrayList<Timing>();

  public void recordTiming(String label) {
    timings.add(new Timing(System.currentTimeMillis(), label));
  }

  public String getTimingString() {
    Iterator<Timing> iter = timings.iterator();
    long startMs = iter.next().timeMs;
    StringBuilder logMsg = new StringBuilder();
    for (Timing timing : timings) {
      logMsg.append(timing.label).append("[").append(timing.timeMs - startMs)
          .append("] ");
    }
    return logMsg.toString();
  }
}
